<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<!--<link href="https://cdn.bootcss.com/cropper/3.1.3/cropper.min.css" rel="stylesheet">-->
		<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="css/home.css">
		<link rel="stylesheet" href="css/base.css">
		<script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.1&services=true"></script>
		<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
		<!--<script src="https://cdn.bootcss.com/cropper/3.1.3/cropper.min.js"></script>-->
		<script type="text/javascript" src="js/index.js"></script>
		<script type="text/javascript" src="js/pattern.js"></script>
		<!--<script type="text/javascript" src="js/personal-setting.js"></script>-->
		<script type="text/javascript" src="js/personInfro.js"></script>
		<title>舆情定制</title>

	</head>

	<body>
		<div class="wholePublic-box">
			<div class="wholePublic-header clearfix">
				<div class="wholePublic-logo fl ">
					<a href="index-logged.html"><img src="images/logo-2.png" /></a>
				</div>
				<div class="wholePublic-header-list fl">
					<ul class="clearfix">
						<li onclick="javascript:window.location='wholePublic-company.html'">全部舆情</li>
						<li onclick="javascript:window.location='my-custom.html'">舆情定制</li>
						<li onclick="javascript:window.location='analysis.html'">分析报告</li>
						<li onclick="javascript:window.location='thinkTank.html'">智库</li>
						<li onclick="javascript:window.location='contactUs.html'">联系我们</li>
					</ul>
				</div>
				<div class="wholePublic-header-right fr">
					<ul class="clearfix">
						<!--<li onclick="javascript:window.location='personal-setting.html'" class="nav_img"><img src="images/header.png" /></li>
						<li onclick="javascript:window.location='personal-setting.html'">Kimi</li>-->
						<li id="line"><img src="images/line-2.png" /></li>
						<li onclick="javascript:window.location='my-custom.html'">我的定制</li>
						<li id="exit"><img src="images/exit-2.png" /></li>
						<li class="setting-icon">
							<a href="company-setting.html"><img src="images/setting-icon.png" /></a>
						</li>
					</ul>

				</div>

			</div>
			<div class="grcolor-box"></div>

			<div class="container">
				<div class="setting-line">
					<ul class="clearfix">
						<li class="setting-line-selected">个人设置</li>
						<li>密码修改</li>
					</ul>
				</div>
				<!--个人设置-->
				<div class="clearfix setting-item" id="person">
					<!--头像设置开始-->
					<div>个人设置</div>
					<div class="person-box">
						<div class="fl ident-img">
							<div class="imgBox">
								<div class="addIcon">+</div>
								<div>头像</div>
							</div>
							<img src="" alt="未显示" id="img" width="200px" height="200px" />
							<div id="container">
								<input type="file" id="headfiles" value="">
							</div>
						</div>
						<!--<div class="head-sculpture fl ">
							<div class="up-header-box">
								<label for="input" class="btn btn-danger" id="">
								<input type="file" id="input" class="sr-only">
								<div class="up-header" id="up-header-1">
									<img src="images/up-header.png" alt="" id="result">
								</div>
								</label>
							</div>
							<div class="queding">
								<div class="up-header" id="up-header-2">
									<img src="" id="photo">
								</div>
								<label onclick="crop()">
									<div class="baocun">
										<span id="save">保存</span>
									</div>
								</label>
							</div>
						</div>-->
						<!--头像设置结束-->
						<div class="up-infro fl" id="myInfro">
							<div><span>姓名</span><input placeholder="输入姓名" class="input-1" id="full_name" /></div>
							<div><span>昵称</span><input placeholder="输入昵称" class="input-1" id="nick_name" /></div>
							<div><span>邮箱</span><input type="email" placeholder="输入常用邮箱" class="input-1" id="ma_email" /></div>
							<div><span>所属行业</span><input placeholder="输入行业A+行业B+..." class="input-2" id="test_industry" /></div>
							<div><span>所属公司</span><input placeholder="输入公司名称" class="input-2" id="company_name" /></div>
							<div class="whole-btn"><button onclick="perSet()">确定</button></div>
						</div>
					</div>
				</div>

				<div class="setting-item" id="updata">
					<div>密码修改</div>
					<div class="password-box">
						<div><span>绑定手机：</span><input placeholder="输入手机号" class="input-4" id="tel_2" /></div>
						<div><span>验证码：</span><input placeholder="输入验证码" class="input-4" id="code" /><input type="button" class="identifying-code " value="获取验证码 " id="identCode_2" onclick="code()"></div>
						<div><span>原始密码：</span><input type="password" placeholder="输入原密码" class="input-4" id="old_pwd"></div>
						<div><span>新设密码：</span><input type="password" placeholder="输入新设定的密码" class="input-4" id="new_pwd"></div>
						<div><span>重新输入新设密码：</span><input type="password" placeholder="输入新设定的密码" class="input-4" id="renew_pwd"></div>					
						<div class="whole-btn"><button onclick="update_pwd()">确定</button></div>
					</div>
				</div>
			</div>

		</div>
	</body>

</html>
<script src="js/imgUp/jquery.min.js"></script>
<script src="js/imgUp/plupload.full.min.js"></script>
<script src="js/imgUp/qiniu.js"></script>
<script src="js/imgUp/myUploader.js"></script>
<script>
	var token = sessionStorage.getItem('token');
	console.log(token);
	var id = JSON.parse(token).id;
	var ma_email = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
	var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
	//个人设置
	$("#myInfro input").focus(function() {
		$(this).css("border", "none");
	});
	function perSet() {
		$("#img").show();
		if($("#full_name").val() == "") {
			$("#full_name").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#nick_name").val() == "") {
			$("#nick_name").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#ma_email").val() == "") {
			$("#ma_email").css("border", "1px solid #d63d3f");
			return false;
		} else if(!ma_email.test($("#ma_email").val())) {
			$("#ma_email").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#test_industry").val() == "") {
			$("#test_industry").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#company_name").val() == "") {
			$("#company_name").css("border", "1px solid #d63d3f");
			return false;
		} else {
			var datas = {
				'id': id,
				'head_img': $("#img").attr("src"),
				'full_name': $("#full_name").val(),
				'nick_name': $("#nick_name").val(),
				'ma_email': $("#email").val(),
				'test_industry': $("#test_industry").val(),
				'company_name': $("#company_name").val(),
			};
			var data = JSON.stringify(datas);
			$.ajax({
				type: "post",
				url: 'http://139.224.208.224:8080/qi-radar/user/updateUser',
				dataType: 'json',
				contentType: "application/json ",
				headers: {
					"Authorization": token
				},
				data: data,
				asycn: false,
				success: function(data) {
					if(data.code == 0) {
						alert("设置成功")
						$(".imgBox").show();
						$("#img").hide();
						$("#full_name").val("");
						$("#nick_name").val("");
						$("#ma_email").val("");
						$("#test_industry").val("");
						$("#company_name").val("");
					} else {
						alert(data.errMsg)
					};
				}
			});
		};
	}

	//获取手机验证码
	function code(){
		var phone = $('#tel_2').val();
		if($('#tel_2').val() == '') {
			$("#tel_2").css("border", "1px solid #d63d3f");
			return false
		}else if(!myreg.test(phone)) {
			$("#tel_2").css("border", "1px solid #d63d3f");
			return false;
		} else {
			var datas = {
				'bind_phone': $('#tel_2').val(),
				'type': 1
			}
			var data = JSON.stringify(datas);
			$.ajax({
				type: "post",
				url: "http://139.224.208.224:8080/qi-radar/user/getSendCode",
				contentType: "application/json",
				data: data,
				success: function(data) {
					settime();
				}
			});
		}

	};

	//倒计时
	var countdown = 60;
	var _generate_code = $("#identCode_2");

	function settime() {
		if(countdown == 0) {
			_generate_code.attr("disabled", false);
			_generate_code.val("获取验证码");
			countdown = 60;
			return false;
		} else {
			$("#identCode_2").attr("disabled", true);
			_generate_code.val("重新发送(" + countdown + ")");
			countdown--;
		}
		setTimeout(function() {
			settime();
		}, 1000);
	};
	
	//修改密码
	$(".password-box input").focus(function() {
		$(this).css("border", "1px solid white");
	});

	function update_pwd() {
		var phone = $('#tel_2').val();
		if($('#tel_2').val() == '') {
			$("#tel_2").css("border", "1px solid #d63d3f");
			return false
		}else if(!myreg.test(phone)) {
			$("#tel_2").css("border", "1px solid #d63d3f");
			return false;
		}else if($("#code").val()=='') {
			$("#code").css("border", "1px solid #d63d3f");
			return false;
		}else if($("#old_pwd").val() == "") {
			$("#old_pwd").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#old_pwd").val() !== "123456") {
			alert("请输入正确的原密码")
			$("#old_pwd").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#new_pwd").val() == "") {
			$("#new_pwd").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#renew_pwd").val() == "") {
			$("#renew_pwd").css("border", "1px solid #d63d3f");
			return false;
		} else if($("#new_pwd").val() !== $("#renew_pwd").val()) {
			alert("请输入正确的新设密码")
			$("#renew_pwd").css("border", "1px solid #d63d3f");
			return false;
		} else {
			var datas = {
				'id': id,
				'password': $("#new_pwd").val(),
				'vicode':$("#code").val(),
			};
			var data = JSON.stringify(datas);
			$.ajax({
				type: "post",
				url: 'http://139.224.208.224:8080/qi-radar/user/updateUserPsw',
				dataType: 'json',
				contentType: "application/json ",
				data: data,
				asycn: false,
				success: function(data) {
					console.log(data)
					if(data.code == 0) {
						alert("修改成功")
					} else {
						alert(data.errMsg)
					};
				}
			});
		};
	}
</script>